/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Frame.java
 *
 * Created on 07/06/2011, 16:34:36
 */
package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import gui.PanelTabuleiro;

/**
 * @author Nushio
 *
 */
public class Frame extends JFrame {

    private static final long serialVersionUID = -1068520962938575120L;
    private Border loginBorder;
    private TitledBorder loginTitledBorder;
    private JPanel loginPanel = new JPanel();

    public static void main(String args[]) {
        new Frame();
    }

    public Frame() {
        try {
            // Making things look pretty!
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        try {
            initGui();
        } catch (Exception e) {
            e.printStackTrace();
        }

        // Setting properties
        Dimension screen = getToolkit().getScreenSize();
        Rectangle bounds = getBounds();
        bounds.width = 800;
        bounds.height = 650;
        bounds.x = (screen.width - bounds.width) / 2;
        bounds.y = (screen.height - bounds.height) / 2;
        setBounds(bounds);

        setResizable(false);

        setTitle("CCCG");
        setupMenu();
        setVisible(true);

        setDefaultCloseOperation(EXIT_ON_CLOSE);

    }

    private void initGui() throws Exception {

        BufferedImage image = ImageIO.read(new File("pics/tabuleiro.png"));
        /*
        * O new File("pics/tabuleiro.png") só vai encontrar a imagem se ela estiver num package dentro da pasta bin
        * Tipo, seria /bin/pics/tabuleiro.png, por que quando vc for gerar o .jar ele só empacota a pasta bin e o que tiver dentro dela, logo nem a pasta src nem a pasta pics são empacotadas!!! xD
        * Quer ver faça o teste!! rsrs
        */
        PanelTabuleiro panel = new PanelTabuleiro(image);
        panel.setBounds(new Rectangle(0, 0, 800, 600));

        this.getContentPane().add(panel, null);
        this.getContentPane().setLayout(null);
    }

    private void setupMenu() {
        JMenu menu = new JMenu("Menu");
        menu.add("Voltar");
        menu.add(new AboutAction());

        // new stuff
        JMenuBar bar = new JMenuBar();
        bar.add(menu);

        setJMenuBar(bar);
    }

    public static class AboutAction extends AbstractAction {

        private static final long serialVersionUID = 5492173304463396871L;

        public AboutAction() {
            super("About");
        }

        public void actionPerformed(ActionEvent e) {
            JTextArea area = new JTextArea(8, 26);
            Font f = new Font(area.getFont().getName(), Font.PLAIN, 13);
            area.setFont(f);

            area.setText("To reescrevendo o codigo q eu axei por ai =D");

            area.setWrapStyleWord(true);
            area.setLineWrap(true);
            area.setEditable(false);

            JPanel p = new JPanel();
            area.setBackground(p.getBackground());

            JOptionPane.showMessageDialog(null, area, "About", JOptionPane.INFORMATION_MESSAGE);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
